package lib.pacificapp.dialog;
 

import lib.pacificapp.framework.R;
import android.app.AlertDialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.WindowManager;
 
/**弹出框工厂**/
public class DialogFactory {
	
 
	  public static AlertDialog getBottomDialog(Context context,int layoutId){
		   DisplayMetrics dm = new DisplayMetrics(); 
		   dm = context.getApplicationContext().getResources().getDisplayMetrics(); 
		   int screenWidth = dm.widthPixels; 
		   return getBottomDialog(context,layoutId,screenWidth,0);
	  }
	  public static AlertDialog getFullBottomDialog(Context context,int layoutId){
		   DisplayMetrics dm = new DisplayMetrics(); 
		   dm = context.getApplicationContext().getResources().getDisplayMetrics(); 
		   int screenWidth = dm.widthPixels; 
		   return getBottomDialog(context,layoutId,screenWidth,dm.heightPixels);
	  }
     public static AlertDialog getBottomDialog(Context context,int layoutId,int width,int height){
   	       final AlertDialog bottomWindow = new AlertDialog.Builder(
					new ContextThemeWrapper(context,
							R.style.Lab_FullscreenTheme)).create();
            // 输入法的设置
			bottomWindow.getWindow().setFlags(
					WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
					WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
               // 设置窗口的动画
			 bottomWindow.getWindow().setWindowAnimations(
				R.style.Lab_Top2bottomAnim);

				ViewGroup bottomXuanZeQuYuWindowLayout = (ViewGroup) LayoutInflater
						.from(context).inflate(layoutId, null);


				// 让底部的宽度和屏幕的宽度一致
				bottomXuanZeQuYuWindowLayout.setMinimumWidth(width);
				if(height>0){
					bottomXuanZeQuYuWindowLayout.setMinimumHeight(height);
				}
				bottomWindow.show();
				// 设置底部布局
				bottomWindow.setContentView(bottomXuanZeQuYuWindowLayout);
                   // 弹出输入法的操作
				bottomWindow.getWindow().clearFlags( WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
                // 设置到底部
				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);
				
				return bottomWindow;

				 
    }

}
